//
//  DNOpenActionVC.swift
//  LunalerApp
//
//  Created by 露乐ios on 2018/2/7.
//  Copyright © 2018年 露乐ios. All rights reserved.
//

import UIKit

fileprivate extension Selector
{
    static let nextAction = #selector(DNOpenActionVC.nextView);
}

class DNOpenActionVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.initUI()
        self.launch()
    }
    
    class func openActionVC() -> DNOpenActionVC
    {
        return DNOpenActionVC();
    }
    
    func initUI(){
        
        let imageView = UIImageView.init(frame: UIScreen.main.bounds);
        // 加载默认启动图，保留加载云端启动图
        if let imageName = UCSCloudDownloadTool.launchImageName() as? NSString {
            imageView.image = UIImage.init(named: imageName as String);
        }
        self.view.addSubview(imageView)
    }
    
    func launch(){
        
        // 可以进行错误上报等
        self.perform(.nextAction, with: nil, afterDelay: 2.0)
    }
    
    @objc func nextView()
    {
        // 检查指纹、手势
        // 检测App是否是第一次启动
        if DNGlobalContext.shareInstance.isNotFirstLaunchThisVesion() == false {
            // 是第一次启动
            let welcomeVC = DNWelcomeVC()
            let delegate = UIApplication.shared.delegate as! AppDelegate
            delegate.window?.rootViewController = welcomeVC
            DNGlobalContext.shareInstance.setNotFirstLaunchThisVesion()
        }else{
            // 不是第一次启动，在这里可以加入是否有未显示的新特性
            let delegate = UIApplication.shared.delegate as! AppDelegate
            let vc : DNTabbarViewController = DNTabbarViewController.shareInstance
            vc.mainTabDelegate = delegate as DNMainTabBarVCDelegate
            delegate.window?.rootViewController = vc
            // 判断用户是否登入
            if DNUserContext.sharedInstance.isLogin == false{
                // 用户未登入,弹出登入界面
                delegate.userLogin()
            }
        }
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
